package main

import (
	"gitee/yinlai/kms-backend/config"
	_ "gitee/yinlai/kms-backend/controllers/initcontrollers"
	middlerwares "gitee/yinlai/kms-backend/middlewares"
	"gitee/yinlai/kms-backend/routers"
	"gitee/yinlai/kms-backend/utils/logs"
	"github.com/gin-gonic/gin"
)

func main() {
	// 1. 加载程序的配置
	// 2. 配置gin
	r := gin.Default()
	if config.RunAsMode == "debug" || config.RunAsMode == "dev" {
		r.Use(middlerwares.Cors)
	} else {
		r.Use(middlerwares.JWTAuth)
	}
	logs.Info(nil, "程序启动成功")

	routers.RegisterRouters(r)
	err := r.Run(config.Port)
	if err != nil {
		logs.Error(nil, "注册路由失败")
	}
}
